package com.os.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

public class ValidCodeControllerM extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	// TODO Auto-generated method stub
	doPost(req, resp);
}
@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
	    req.setCharacterEncoding("utf8");
	    resp.setCharacterEncoding("utf8");
	    PrintWriter pw=resp.getWriter();
		List<String> validCodes=new ArrayList<String>();
		validCodes.add("hel5");
		validCodes.add("j6va");
		validCodes.add("wr2d");
		validCodes.add("La3L");
		validCodes.add("haha");
		validCodes.add("s4g6");
		validCodes.add("n65h");
		validCodes.add("u7jf");
		Random random=new Random();
		int rnum=random.nextInt(validCodes.size());
		String tempCode=validCodes.get(rnum);
		//HttpSession session=req.getSession();
		//session.setAttribute("tmcode", tempCode);
		JSONObject j=new JSONObject();
		j.put("tcode",tempCode);
		pw.write(j.toString());
	}
}
